package com.ruoyi.web.controller.shaketicket;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shaketicket.domain.ShaketicketRecord;
import com.ruoyi.shaketicket.service.IShaketicketRecordService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.base.AjaxResult;

/**
 * 摇一摇抽奖记录 信息操作处理
 * 
 * @author lzy
 * @date 2019-03-01
 */
@Controller
@RequestMapping("/shaketicket/shaketicketRecord")
public class ShaketicketRecordController extends BaseController
{
    private String prefix = "shaketicket/shaketicketRecord";
	
	@Autowired
	private IShaketicketRecordService shaketicketRecordService;
	
	@RequiresPermissions("shaketicket:shaketicketRecord:view")
	@GetMapping()
	public String shaketicketRecord()
	{
	    return prefix + "/shaketicketRecord";
	}
	
	/**
	 * 查询摇一摇抽奖记录列表
	 */
	@RequiresPermissions("shaketicket:shaketicketRecord:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ShaketicketRecord shaketicketRecord)
	{
		startPage();
        List<ShaketicketRecord> list = shaketicketRecordService.selectShaketicketRecordList(shaketicketRecord);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出摇一摇抽奖记录列表
	 */
	@RequiresPermissions("shaketicket:shaketicketRecord:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShaketicketRecord shaketicketRecord)
    {
    	List<ShaketicketRecord> list = shaketicketRecordService.selectShaketicketRecordList(shaketicketRecord);
        ExcelUtil<ShaketicketRecord> util = new ExcelUtil<ShaketicketRecord>(ShaketicketRecord.class);
        return util.exportExcel(list, "shaketicketRecord");
    }
	
	/**
	 * 新增摇一摇抽奖记录
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存摇一摇抽奖记录
	 */
	@RequiresPermissions("shaketicket:shaketicketRecord:add")
	@Log(title = "摇一摇抽奖记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ShaketicketRecord shaketicketRecord)
	{		
		return toAjax(shaketicketRecordService.insertShaketicketRecord(shaketicketRecord));
	}

	/**
	 * 修改摇一摇抽奖记录
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		ShaketicketRecord shaketicketRecord = shaketicketRecordService.selectShaketicketRecordById(id);
		mmap.put("shaketicketRecord", shaketicketRecord);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存摇一摇抽奖记录
	 */
	@RequiresPermissions("shaketicket:shaketicketRecord:edit")
	@Log(title = "摇一摇抽奖记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ShaketicketRecord shaketicketRecord)
	{		
		return toAjax(shaketicketRecordService.updateShaketicketRecord(shaketicketRecord));
	}
	
	/**
	 * 删除摇一摇抽奖记录
	 */
	@RequiresPermissions("shaketicket:shaketicketRecord:remove")
	@Log(title = "摇一摇抽奖记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(shaketicketRecordService.deleteShaketicketRecordByIds(ids));
	}
	
}
